package com.hanxiaozhang.base.service.impl;

import com.hanxiaozhang.constant.DelFlagEnum;
import com.hanxiaozhang.security.CurrentUserUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import com.hanxiaozhang.base.dao.LogDao;
import com.hanxiaozhang.base.entity.LogEntity;
import com.hanxiaozhang.base.service.LogService;
import org.springframework.transaction.annotation.Transactional;


/**
 * 系统日志
 *
 * @author hanxiaozhang
 * @email hanxiaozhang2018@sina.com
 * @date 2021-04-08
 */
@Service
@EnableAsync
public class LogServiceImpl implements LogService {

    @Resource
    private LogDao logDao;

    @Override
    public LogEntity get(Long logId) {
        return logDao.get(logId);
    }

    @Override
    public List<LogEntity> list(Map<String, Object> map) {
        return logDao.list(map);
    }

    @Async
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(LogEntity log) {
        log.setCreateBy(CurrentUserUtil.getUserName())
                .setCreateDate(LocalDateTime.now())
                .setDelFlag(DelFlagEnum.NORMAL.getCode());
        logDao.save(log);
    }


    @Override
    public int remove(Long logId) {
        return logDao.remove(logId);
    }

    @Override
    public int batchRemove(Long[] logIds) {
        return logDao.batchRemove(logIds);
    }

}
